Skip to content

Sankey diagram: largest-revenue-first ordering with sequential expense allocation and Leftover node#68

Merged
JoeProgrammer88 merged 2 commits intomainfrom
copilot/enhance-sankey-diagram
Apr 1, 2026
Merged

Sankey diagram: largest-revenue-first ordering with sequential expense allocation and Leftover node#68
JoeProgrammer88 merged 2 commits intomainfrom
copilot/enhance-sankey-diagram

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Apr 1, 2026

The Sankey diagram previously distributed each revenue source proportionally across all expenses simultaneously, with no ordering guarantee and no representation of surplus revenue.

Changes

  • Revenue ordering — revenue nodes are now sorted descending by amount so the largest source always appears at the top
  • Sequential allocation — each revenue source exhausts expenses top-to-bottom before the next source picks up; a source only touches an expense category if prior sources left it unfilled
  • Leftover node — when total revenue exceeds total expenses, the surplus is collected into a grey "Leftover" node at the bottom of the right side
  • Accurate flow bands — band heights are now computed proportionally against each node's actual allocated amount rather than a global total, so bands fill their source/destination nodes exactly

Allocation logic

for (const [revCat, revAmount] of revEntries /* sorted desc */) {
    let remaining = revAmount;
    for (const expCat of expenseOrder) {
        if (remaining < ALLOC_EPSILON) break;
        const need = remainingExpenses[expCat] ?? 0;
        if (need < ALLOC_EPSILON) continue;
        const allocated = Math.min(remaining, need);
        flows.push({ revCat, expCat, amount: allocated });
        remainingExpenses[expCat] -= allocated;
        remaining -= allocated;
    }
    if (remaining > ALLOC_EPSILON)
        flows.push({ revCat, expCat: 'Leftover', amount: remaining });
}

Result

Sankey diagram showing Salary covering all expenses with remaining revenue flowing to Leftover

Copilot AI linked an issue Apr 1, 2026 that may be closed by this pull request
…tion, Leftover node

Agent-Logs-Url: https://github.com/SpeakingInBits/TaskManagerWeb/sessions/00eb5a91-6a78-4f35-8691-4be435f3c094

Co-authored-by: JoeProgrammer88 <7156063+JoeProgrammer88@users.noreply.github.com>
Copilot AI changed the title [WIP] Enhance Sankey diagram to prioritize largest revenue sources Sankey diagram: largest-revenue-first ordering with sequential expense allocation and Leftover node Apr 1, 2026
Copilot AI requested a review from JoeProgrammer88 April 1, 2026 01:11
@JoeProgrammer88 JoeProgrammer88 marked this pull request as ready for review April 1, 2026 01:15
@JoeProgrammer88 JoeProgrammer88 merged commit 06d1696 into main Apr 1, 2026
1 check passed
@JoeProgrammer88 JoeProgrammer88 deleted the copilot/enhance-sankey-diagram branch April 1, 2026 01:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Sankey Diagram Enhancement

2 participants